﻿using System;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Microsoft.Win32;
using Resn.WhuPub.BLL;

namespace Resn.WhuPub.WPFClientUI
{
        /// <summary>
        /// ManageExamineePage.xaml 的交互逻辑
        /// </summary>
        public partial class ManageVisitsPage : Page
        {
                private readonly GlobalManager _gm = GlobalManager.Instance;

                public ManageVisitsPage()
                {
                        InitializeComponent();
                }

                private void Page_Loaded(object sender, RoutedEventArgs e)
                {
                        if (_gm.LoginEmployee == null)
                        {
                                MessageBox.Show("请先登录系统");
                                NavigationService.Navigate(new Uri("StartPage.xaml", UriKind.Relative));
                        }

                        _gm.Visit = null;

                        LayoutRoot.DataContext = _gm;
                }

                private void CreateButton_Click(object sender, RoutedEventArgs e)
                {
                        if (_gm.TravelFlow == null)
                        {
                                MessageBox.Show("请选择要新建拜访事件的差旅流程");
                                _gm.TravelFlows = new ObservableCollection<TravelFlow>(_gm.LoginEmployee.TravelFlows);
                                NavigationService.Navigate(new Uri("ManageTravelFlowsPage.xaml", UriKind.Relative));
                        }
                        else
                        {
                                new CreateVisitWindow().ShowDialog();
                        }
                }

                private void UpdateButton_Click(object sender, RoutedEventArgs e)
                {
                        if (_gm.Visit == null)
                        {
                                MessageBox.Show("请选择要编辑的拜访事件");
                                return;
                        }

                        //new UpdateVisitWindow().ShowDialog();
                        MessageBox.Show("待测试");
                }

                private void DeleteButton_Click(object sender, RoutedEventArgs e)
                {
                        // 在此处新建事件处理程序实现。
                        if (_gm.Visit == null)
                        {
                                MessageBox.Show("请选择要删除的拜访事件");
                                return;
                        }

                        if (
                                MessageBox.Show("确定要删除" + _gm.Visit + "及其他信息吗？",
                                                "警告", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                        {
                                _gm.Visit.Delete();
                                _gm.Visits.Remove(_gm.Visit);
                        }
                }

                private void SearchButton_Click(object sender, RoutedEventArgs e)
                {
                        //new SearchVisitWindow().ShowDialog();
                        MessageBox.Show("待测试");
                }
        }
}